package Day7_07_30;

//返回字符串的副本，忽略前导空白和尾部空白
public class Trim {
	public static String trimTest(String strArg) {
		char[] str = strArg.toCharArray();
		int beginIndex = 0;
		int endIndex = str.length - 1;
		while (beginIndex < str.length && str[beginIndex] == ' ') {
			beginIndex++;
		}
		if (beginIndex == str.length) {
			return "是空的字符串";
		}
		while (endIndex >= 0 && str[endIndex] == ' ') {
			endIndex--;
		}
		String subStr = strArg.substring(beginIndex, endIndex + 1);
		return subStr;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String str1 = "  天青色等烟雨，而我在等你       ";// 2,7
		String str2 = " 多冷呐";
		String str3 = " 我在东北玩泥巴";
		String str4 = " 虽然东北不大 ";
		String str6 = "我在大连没有家 ";
		String str5 = "     ";
		System.out.println(trimTest(str1));
		System.out.println(trimTest(str2));
		System.out.println(trimTest(str3));
		System.out.println(trimTest(str4));
		System.out.println(trimTest(str6));
		System.out.println(trimTest(str5));
	}
}
